package com.appoint.web.controller.buss;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.appoint.common.annotation.Log;
import com.appoint.common.core.controller.BaseController;
import com.appoint.common.core.domain.AjaxResult;
import com.appoint.common.enums.BusinessType;
import com.appoint.buss.domain.EpiparaRnaSeq;
import com.appoint.buss.service.IEpiparaRnaSeqService;
import com.appoint.common.utils.poi.ExcelUtil;
import com.appoint.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * rna_seqController
 *
 * @author appoint
 * @date 2023-01-10
 */
@RestController
@RequestMapping("/buss/rnaSeq")
public class EpiparaRnaSeqController extends BaseController
{
    @Autowired
    private IEpiparaRnaSeqService epiparaRnaSeqService;

    /**
     * 查询rna_seq列表
     */
    @PreAuthorize("@ss.hasPermi('buss:rnaSeq:list')")
    @GetMapping("/list")
    public TableDataInfo list(EpiparaRnaSeq epiparaRnaSeq)
    {
        startPage();
        List<EpiparaRnaSeq> list = epiparaRnaSeqService.selectEpiparaRnaSeqList(epiparaRnaSeq);
        return getDataTable(list);
    }

    /**
     * 导出rna_seq列表
     */
    @PreAuthorize("@ss.hasPermi('buss:rnaSeq:export')")
    @Log(title = "rna_seq", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EpiparaRnaSeq epiparaRnaSeq)
    {
        List<EpiparaRnaSeq> list = epiparaRnaSeqService.selectEpiparaRnaSeqList(epiparaRnaSeq);
        ExcelUtil<EpiparaRnaSeq> util = new ExcelUtil<EpiparaRnaSeq>(EpiparaRnaSeq.class);
        util.exportExcel(response, list, "rna_seq数据");
    }

    /**
     * 获取rna_seq详细信息
     */
    @PreAuthorize("@ss.hasPermi('buss:rnaSeq:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(epiparaRnaSeqService.getById(id));
    }

    /**
     * 新增rna_seq
     */
    @PreAuthorize("@ss.hasPermi('buss:rnaSeq:add')")
    @Log(title = "rna_seq", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EpiparaRnaSeq epiparaRnaSeq)
    {
        return toAjax(epiparaRnaSeqService.insertEpiparaRnaSeq(epiparaRnaSeq));
    }

    /**
     * 修改rna_seq
     */
    @PreAuthorize("@ss.hasPermi('buss:rnaSeq:edit')")
    @Log(title = "rna_seq", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EpiparaRnaSeq epiparaRnaSeq)
    {
        return toAjax(epiparaRnaSeqService.updateEpiparaRnaSeq(epiparaRnaSeq));
    }

    /**
     * 删除rna_seq
     */
    @PreAuthorize("@ss.hasPermi('buss:rnaSeq:remove')")
    @Log(title = "rna_seq", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(epiparaRnaSeqService.deleteEpiparaRnaSeqByIds(ids));
    }

    @Log(title = "信息导入", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('buss:rnaSeq:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<EpiparaRnaSeq> util = new ExcelUtil<>(EpiparaRnaSeq.class);
        List<EpiparaRnaSeq> list = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String fileName = file.getOriginalFilename();
        fileName  =fileName.substring(0,fileName.lastIndexOf("."));
        String message = epiparaRnaSeqService.importUser(list, updateSupport, operName,fileName);
        return AjaxResult.success(message);
    }
}
